package com.eedi.framework.social.controller.sys;

import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.common.util.object.BeanUtils;
import com.eedi.framework.social.controller.sys.vo.client.SysSocialClientPageReq;
import com.eedi.framework.social.controller.sys.vo.client.SysSocialClientResp;
import com.eedi.framework.social.controller.sys.vo.client.SysSocialClientSaveReq;
import com.eedi.framework.social.dal.dataobject.SysSocialClientDO;
import com.eedi.framework.social.service.SysSocialClientService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.eedi.framework.common.pojo.CommonResult.success;

@Tag(name = "系统界面 - 社交客户端")
@RestController
@RequestMapping("/social-client")
@Validated
public class SysSocialClientController {

    @Resource
    private SysSocialClientService sysSocialClientService;

    @PostMapping("/create")
    @Operation(summary = "创建社交客户端")
    @PreAuthorize("@ss.hasPermission('sys:social-client:create')")
    public CommonResult<String> createSocialClient(@Valid @RequestBody SysSocialClientSaveReq createReqVO) {
        return success(sysSocialClientService.createSocialClient(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新社交客户端")
    @PreAuthorize("@ss.hasPermission('sys:social-client:update')")
    public CommonResult<Boolean> updateSocialClient(@Valid @RequestBody SysSocialClientSaveReq updateReqVO) {
        sysSocialClientService.updateSocialClient(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除社交客户端")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('sys:social-client:delete')")
    public CommonResult<Boolean> deleteSocialClient(@RequestParam("socialClientId") String id) {
        sysSocialClientService.deleteSocialClient(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得社交客户端")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('sys:social-client:query')")
    public CommonResult<SysSocialClientResp> getSocialClient(@RequestParam("socialClientId") String id) {
        SysSocialClientDO client = sysSocialClientService.getSocialClient(id);
        return success(BeanUtils.toBean(client, SysSocialClientResp.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得社交客户端分页")
    @PreAuthorize("@ss.hasPermission('sys:social-client:query')")
    public CommonResult<PageResult<SysSocialClientResp>> getSocialClientPage(@Valid SysSocialClientPageReq pageVO) {
        PageResult<SysSocialClientDO> pageResult = sysSocialClientService.getSocialClientPage(pageVO);
        return success(BeanUtils.toBean(pageResult, SysSocialClientResp.class));
    }

}
